package com.usian.controller;

import com.usian.pojo.TbItem;
import com.usian.pojo.TbItemDesc;
import com.usian.service.TbItemService;
import com.usian.utils.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author chen
 * @date 2021/1/9 - 11:34 - 星期六
 * @project usian_parent
 * @package com.usian.controller
 * @by GGbomd猪猪侠
 */
@RestController
public class TbItemController {

    @Autowired
    private TbItemService tbItemService;

    /**
     * 商品列表查询
     * @param page  页码
     * @param rows  每页显示的条数
     * @return
     */
    @RequestMapping("/selectTbItemAllByPage")
    public PageResult selectTbItemAllByPage(Integer page, Integer rows){
        return tbItemService.selectTbItemAllByPage(page,rows);
    }

    /**
     * 商品的添加
     * @param tbItem
     * @param desc
     * @param itemParams
     * @return
     */
    @RequestMapping("/insertTbItem")
    public Integer  insertTbItem(@RequestBody TbItem tbItem, @RequestParam String desc , @RequestParam String itemParams){
        return tbItemService.insertTbItem(tbItem,desc,itemParams);
    }

    /**
     * 商品的删除
     * @param itemId
     * @return
     */
    @RequestMapping("/deleteItemById")
    public Integer deleteItemById(@RequestParam Long itemId){
        return tbItemService.deleteItemById(itemId);
    }

    /**
     * 根据商品 ID 查询商品，商品分类，商品描述，商品规格参数
     * @param itemId
     * @return
     */
    @RequestMapping("/preUpdateItem")
    public Map<String,Object> preUpdateItem(@RequestParam("itemId") Long itemId){
        return this.tbItemService.preUpdateItem(itemId);
    }

    /**
     * 根据商品id去修改
     * @param tbItem
     * @param desc
     * @param itemParams
     * @return
     */
    @RequestMapping("/updateTbItem")
    public Integer updateTbItem(@RequestBody TbItem tbItem, @RequestParam String desc , @RequestParam String itemParams){
        return tbItemService.updateTbItem(tbItem,desc,itemParams);
    }

    /**
     * 查询商品基本详细信息
     * @param itemId
     * @return
     */
    @RequestMapping("/selectItemInfo")
    public TbItem selectItemInfo(@RequestParam Long itemId){
        return tbItemService.selectItemInfo(itemId);
    }

    /**
     * 根据商品 ID 查询商品描述
     * @param itemId
     * @return
     */
    @RequestMapping("/selectItemDescByItemId")
    public TbItemDesc selectItemDescByItemId(@RequestParam Long itemId){
        return tbItemService.selectItemDescByItemId(itemId);
    }

}
